<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // https://leetcode-cn.com/problems/single-number-ii/
        // map迭代的类数组用Array.from()转换为数组
        // 普通对象用Object.keys()来转换为数组
        var singleNumber = function(nums) {
            let map = new Map();
            for (let item of nums) {
                if (!map.has(item)) {
                    let count = 1;
                    map.set(item, count);
                } else {
                    let count = map.get(item);
                    map.set(item, count + 1);
                }
            }
            return Array.from(map.entries()).filter(item => {
                return item[1] === 1;
            })[0][0]
        };
        singleNumber([0,1,0,1,0,1,99]);
    </script>
</body>
</html>